package com.service.bank.controller;

import com.client.common.service.SmsService;
import com.client.model.pojo.bank.ArBankcard;
import com.client.model.pojo.bank.ArCardtype;
import com.client.model.pojo.bank.ArElectronic;
import com.client.model.pojo.bank.TElectronicCard;
import com.client.model.vo.common.Result;
import com.client.model.vo.common.ResultCodeEnum;
import com.client.model.vo.creditLoanVo.ArBanksVo;
import com.client.model.vo.deposit.ArBankcardVo;
import com.client.model.vo.deposit.ArElectoronicsVo;
import com.github.yulichang.wrapper.resultmap.ResultList;
import com.service.bank.service.ArBankcardService;
import com.service.bank.service.ArElectronicService;
import com.service.bank.service.TElectronicCardService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 周佳辉
 * @date 2024/4/2
 */
@RestController
@RequestMapping("/airui/api/bank")
@Tag(name = "银行卡绑卡管理")
public class BankcardController {

    @Autowired
    private TElectronicCardService electronicCardService;

    @Autowired
    private SmsService smsService;

    @Autowired
    private ArBankcardService arBankcardService;

    @Autowired
    private ArElectronicService arElectronicService;

    @PostMapping("/send")
    @ResponseBody
    @Operation(summary = "发送验证码")
    public Result<String> send(@RequestParam(value = "phone") String phone) {
        boolean send = smsService.send(phone);
        if (send) {
            return Result.build(null, ResultCodeEnum.SUCCESS);
        } else {
            return Result.build(null, ResultCodeEnum.DATA_ERROR);
        }
    }

    @PostMapping("/savebankcard")
    @Operation(summary = "绑定银行卡")
    public Result<TElectronicCard>  saveBankCard(@RequestBody ArBankcardVo arBankcardVo,
                                                 @RequestHeader String token){
        System.err.println(arBankcardVo);
        this.electronicCardService.saveBankCard(arBankcardVo,token);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }



    @GetMapping("/getbankcardlist")
    @Operation(summary = "获取银行卡列表")
    public Result<List<ArBanksVo>> getBankCardList(@RequestHeader String token){
        List<ArBanksVo> list = this.arBankcardService.getBankCardList(token);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/getbankcardbycid/{cid}")
    @Operation(summary = "根据cid获取银行卡类型")
    public Result<ArCardtype> getBankCardByCid(@PathVariable(value = "cid") Long cid){
        System.err.println(cid);
        ArCardtype arCardtype = this.arBankcardService.getBankCardByCid(cid);
        return Result.build(arCardtype, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/savetixian")
    @Operation(summary = "提现")
    public Result savetixian(@RequestHeader String token,@RequestBody ArElectoronicsVo arElectoronicsVo){
        System.err.println(arElectoronicsVo);
        this.electronicCardService.savetixian(token,arElectoronicsVo);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }


    @GetMapping("/getquan")
    @Operation(summary = "获取全部信息")
    public Result<ArBankcard> getBankCardKQuan(){
        List<ArBankcard> arBankcards =  this.arBankcardService.list();
        System.out.println(arBankcards);
        return Result.build(arBankcards,ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/geteid")
    @Operation(summary = "根据eid获取电子账户")
    public Result<ArElectronic>  getEid(@RequestHeader String token){
        ArElectronic arElectronic = this.arElectronicService.getEid(token);
        return Result.build(arElectronic,ResultCodeEnum.SUCCESS);
    }
}
